#include <stdio.h>
#include <stdlib.h>

struct Student // 声明结构体类型struct Student
{
    int num;
    char name[20];
    float score;
};

// 比较函数，用于qsort函数的调用，对学生成绩进行排序
int compare(const void *s1, const void *s2) {
    struct Student *ps1 = (struct Student *)s1;
    struct Student *ps2 = (struct Student *)s2;
    return -(ps1->score - ps2->score);
}

int main() {
    // 定义结构体数组并初始化
    struct Student stu[] = {
        {10101, "Zhang", 78},
        {10103, "Wang", 98.5},
        {10106, "Li", 86},
        {10108, "Ling", 73.5},
        {10110, "Sun", 100}
    }; 
    const int n = sizeof(stu) / sizeof(struct Student);
    // 调用qsort函数对stu数组进行排序
    qsort(stu, n, sizeof(struct Student), compare);
    // 输出排序后的结果
    for (int i = 0; i < n; i++) {
        printf("%6d %8s %6.2f\n", stu[i].num, stu[i].name, stu[i].score);
    }
    printf("\n");
    return 0;
}
